package jiejie.jianzhioffer;

public class offer11 {
    public static void main(String[] args) {
        int[] nums={3,1,3};
        System.out.println(minArray(nums));

    }

    /**
     * 旋转数组最小值
     * @param numbers
     * @return
     */
    public static int minArray(int[] numbers) {
        if(numbers.length==0)
            return 0;
        int left=0;
        int right=numbers.length-1;
        while(left<right){
            int mid=(left+right)/2;
            if(numbers[mid]>numbers[right]){
                left=mid+1;//已经比right处大了，所以mid+1
            }
            else if(numbers[mid]<numbers[right]){
                right=mid;//有可能是最小值的，所以要考虑到mid，不能mid-1
            }
            else
                right--;
        }
        return numbers[left];
    }
}